package com.fan.shop.businesslogic;

import com.fan.shop.domain.Item;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.ItemService;

public class ItemDeleteProcess extends ProcExec<Integer> {

	private String itemCode;
	private ItemService itemService;
	
	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public ItemService getItemService() {
		return itemService;
	}

	public void setItemService(ItemService itemService) {
		this.itemService = itemService;
	}

	@Override
	public Integer processImpl() {
		
		if(!itemService.hasItem(itemCode))
		{
			setErrorMessage("Item: " + itemCode + " doesn't exist!");
			return ShopGlobalVariables.FAILED;
		}
		else
		{
			Item item = itemService.getItem(itemCode);
			itemService.deleteItem(item);
			return ShopGlobalVariables.SUCCESS;
		}
	}

}
